<template>
	<view class="container">
		<view class="mp-search-box" @click="toSearch">
			<input class="ser-input" type="text" placeholder="请输入搜索的内容" disabled />
		</view>
		<view style="margin-top: 100upx;"></view>

		<view v-if="bannerList.length>0">
			<swiper class="swiper-content" interval="5000" autoplay="true"
			    indicator-dots="true" circular="true" indicator-active-color="#ffffff">
			    <swiper-item v-for="(item, index) in bannerList" :key="index">
			        <view class="img-content" >
			            <image class="swiper-img" :src="item.imageUrl"  mode="aspectFill" ></image>
			            <!-- <view>¥23.00</view> -->
			        </view>
			    </swiper-item>
			</swiper>
		</view>
		<view v-else></view>
		
		<view style="margin-top: 20upx;"></view>


		<u-subsection :list="list" mode="button" :current="type" activeColor="#f9ae3d" @change="change4"
			style="margin-top: 10upx;">
		</u-subsection>


		<!-- 资源内容 -->
		<view style="display: flex;flex-direction: column;">
			<view style="display: flex;flex-direction: row;margin-left: 24upx;margin-top: 20upx;
				background-color: #ffffff;margin-right: 24upx;" v-for="(item,index) in resourceList" :key="index" @click="toDetail(item.id)">
				<image :src="item.cover"
					style="width: 400upx;height: 200upx;border-radius: 20upx;box-shadow: 2upx  2upx 2upx #ababab;"
					mode=""></image>

				<view style="display: flex;flex-direction: column;margin-left: 24upx;width: 100%;">
					<view style="font-size: 28upx;font-weight: 500;color: #252526;margin-top: 5upx;">{{item.title}}
					</view>
					<view style="font-size: 25upx;color: #A6A6A6;margin-top: 10upx;">{{item.title}}</view>

					<view style="display: flex;flex-direction: row;align-items: center;">
						<view style="font-weight: 700;color: #FF4850;font-size: 20px;margin-bottom: 8upx;"><text
								style="font-size: 10px;">
								￥
							</text>{{item.price}}</view>
						<view style="color: #A0A0A0;font-size: 20upx;margin-left: 15upx;text-decoration: line-through">
							{{item.originPrice}}积分
						</view>
					</view>
					<view style="display: flex;flex-direction: row;;align-items: center;
					justify-content: space-between;margin-bottom: 10upx;">
						<view style="display: flex;flex-direction: row;align-items: center;">
							<view style="background-color: #252526;color: #EDCF87;
							font-size: 18upx;height: 32upx;line-height: 32upx;
							text-align: center;border-bottom-left-radius: 16upx;border-top-left-radius: 16upx;padding-left: 10upx;padding-right: 10upx;">
							<text v-if="item.price===0">免费</text>
							<text v-else>付费</text>
							
							</view>
							<view style="background-color: #EDCF87;color: #252526;
							font-size: 18upx;height: 32upx;line-height: 32upx;
							text-align: center;border-bottom-right-radius: 16upx;border-top-right-radius: 16upx;padding-left: 10upx;padding-right: 10upx;">
							<text >{{item.resourceTypeName}}</text>
							
							</view>
						</view>
						<view style="font-size: 25upx;color: #A6A6A6;margin-right: 40upx;">{{item.viewCount}}人浏览</view>
					</view>
				</view>
			</view>
		</view>

		<view style="margin-top: 200upx;"></view>
		<view v-show="isEmpty">
			<u-empty mode="search" icon="http://cdn.uviewui.com/uview/empty/search.png">
			</u-empty>
		</view>



	</view>
</template>

<script>
	import {
		banner_list
	} from '../../api/banner.js'
	import {
		resource_code_list,resource_code_detail
	} from '../../api/resource_code.js'
	export default {
		data() {
			return {
				list2: [],
				list: ['全部', '小程序', '游戏源码', '应用源码', '实用工具'],
				type: 0,
				isEmpty: false,
				bannerList: [],
				resourceList: [],
				pageNumber: 2,
				list1: [{
					name: '默认',
				}, {
					name: '最新',
				}, {
					name: '推荐'
				}, {
					name: '热销'
				}]
			}
		},
		onLoad() {
			// let type=uni.getStorageSync('resource_type')
			// console.log(type)
			this.getBannerList()
			this.getResourceList(0)


		},


		onReachBottom() {
			let params = {}
			this.isEmpty=false
			params.type = this.type;
			params.current = this.pageNumber
			params.pageSize = 10;
			resource_code_list(params).then(res => {
				if(res.data.length > 0){
					this.resourceList = this.resourceList.concat(res.data)
					this.pageNumber = this.pageNumber + 1;
				}else{
					this.isEmpty=false
				}
				
			})
		},
		// onShow() {
		// 	let type = uni.getStorageSync('resource_type')
		// 	this.type = type
		// 	console.log(type)
		// 	this.getResourceList(type)
		// },

		methods: {
			
			
			
			toDetail(id){
				uni.navigateTo({
					url: `/pages/product/product?id=${id}`
				})
			},
			getResourceList(type) {

				let params = {}
				params.type = type
				params.pageSize = 10;
				resource_code_list(params).then(res => {
					this.resourceList = res.data
				})
			},

			getBannerList() {
				let params = {}
				params.type = 1
				params.location = 2
				banner_list(params).then(res => {
					console.log(res.data)
					this.bannerList = res.data
				
				})

			},
			toSearch() {
				uni.navigateTo({
					url: '../search/search'
				})
			},
			change4(index) {
				this.resourceList = []
				let params = {}
				this.type = index
				params.type = index
				params.current = 1
				params.pageSize = 10;
				resource_code_list(params).then(res => {
					if (res.data.length > 0) {
						this.resourceList = res.data
					} else {
						this.resourceList = []
						this.isEmpty = true
					}

				})

			}
		}
	}
</script>

<style lang='scss'>
	.container {
		background-color: #f5f5f5;
	}

	.mp-search-box {
		position: absolute;
		left: 0;
		top: 20rpx;
		z-index: 9999;
		width: 100%;
		padding: 0 20rpx;

		.ser-input {
			flex: 1;
			height: 60rpx;
			line-height: 60rpx;
			text-align: center;
			font-size: 28rpx;
			color: $font-color-base;
			border-radius: 30rpx;
			/* background: rgba(255, 255, 255, 0.15); */
			background-color: #eeeeee;
		}
	}
</style>
